<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="../../../plugin/layui/css/layui.css">
    <link rel="stylesheet" href="../../../plugin/ztree/css/metroStyle/metroStyle.css">
    <script type="text/javascript" src="../../../plugin/jquery/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="../../../plugin/layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../../plugin/ztree/js/jquery.ztree.core.js"></script>
    <script type="text/javascript" src="../../../plugin/ztree/js/jquery.ztree.excheck.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../../plugin/tools/tool.js"></script>
</head>

<body>
<div class="x-body">
    <div class="layui-form layui-form-pane" style="margin-left: 20px;">
        <div style="width:100%;height:500px;overflow: auto;">
            <div style="padding-right: 15px;padding-left: 15px;">
                <div class="layui-input-inline" style="padding-top: 10px;">
                    <button id="addItem" class="layui-btn layui-btn-normal layui-input-inline">
                        <i class="layui-icon">&#xe608;</i>添加问题
                    </button>

                    <input lay-filter="type" type="radio" name="type" value="0" title="需求" checked>
                    <input lay-filter="type" type="radio" name="type" value="1" title="缺陷" >
                    <input lay-filter="type" type="radio" name="type" value="2" title="任务">
                </div>
                <table id="issueList" class="layui-hide" lay-filter="issueList"></table>
            </div>
        </div>
        <div style="width: 100%;height: 55px;background-color: white;border-top:1px solid #e6e6e6;position: fixed;bottom: 1px;margin-left:-20px;">
            <div class="layui-form-item" style=" float: right;margin-right: 30px;margin-top: 8px">
                <button class="layui-btn layui-btn-primary" id="close">
                    取消
                </button>
            </div>
        </div>
    </div>
</div>

<!-- 表格按钮 -->
<script type="text/html" id="toolBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script>
    layui.use(['form', 'layer', 'layedit'], function () {
        $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;
        var type = '0';

        var data = window.parent.data;
        $("#id").val(data.id);
        $("#name").html(data.name);

        // 新增问题
        $("#addItem").click(function(){
            addItem();
        });

        //方法级渲染
        parent.issueMainTable = layui.table.render({
            id: 'issueList',
            elem: '#issueList'
            , url: '../../../pdms/iteration/selectIssueList'
            ,where:{
                issueType:type,
                iterationId:data.id
            }
            , cols: [[
                {checkbox: true, fixed: true, width: '5%'}
                , {field: 'name', title: '问题名称', width: '20%', sort: true}
                , {field: 'content', title: '问题内容', width: '20%', sort: true}
                , {field: 'createDateText', title: '创建时间', width: '20%', sort: true}
                , {field: 'statusText', title: '状态', width: '10%', sort: true}
                , {field: 'remark', title: '操作', width: '15%', toolbar: "#toolBar"}
            ]]
            , page: true
            , height: 400
            , done: function(res, curr, count){
                /*$("[tag='name']").click(function () {
                    addIssue();
                });*/
            }
        });

        function addItem() {
            window.data = parent.data;
            // 此处有坑parent,子页面获取的parent为iterationList.html
            layer.open({
                type: 2,
                area: ['1000px', '500px'],
                title: '关联问题',
                content: 'add-issue-iteration.html'
            });
        }

        form.render();
        // 单选按钮切换
        form.on('radio(type)', function(data){
            type = data.value;
            layui.table.reload('issueList',{
                where:{
                    issueType:type
                }
            });
        });

        //监听工具条
        layui.table.on('tool(issueList)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除[<label style="color: #00AA91;">' + data.name + '</label>]?', function () {
                    $.post('../../../pdms/iteration/removeIssue',{id:data.id},function(data){
                        layer.msg('删除成功');
                        layui.table.reload('issueList');
                    },'json');
                });
            }
        });

        $('#close').click(function (){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

    });
</script>
</body>

</html>
